<?php
/**
 * Created by PhpStorm.
 * User: hualei
 * Date: 2015/5/31
 * Time: 10:44
 */
namespace app\modules\h5cargo\controllers;
use Yii;
use yii\web\Controller;
use app\modules\h5cargo\models\JSSDK;

class NologinindexController extends Controller
{
    public $enableCsrfValidation = false;
    public $layout = 'stair_layout';

    //登录
    public function actionLogin()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='用户登录';
        return $this->render('login');
    }
    //注册
    public function actionRegister()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='用户注册';
        return $this->render('register');
    }

    //泊车首页
    public function actionParkindex()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='泊车';
        return $this->render('parkIndex');
    }
    //租车首页
    public function actionRentalcar()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='租车';
        return $this->render('rentalCar');
    }
    //爱车列表
    public function actionMycarlist()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='爱车列表';
        return $this->render('myCarList');
    }
    //福利
    public function actionWelfare()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='福利';
        return $this->render('welfare');
    }
//福利
    public function actionReturnpageparkcar()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='支付回调';
        return $this->render('returnpage_parkcar');
    }
    //福利
    public function actionReturnpagerentcar()
    {
        //$view = Yii::$app->view;
        //$view->params['layoutTitle']='支付回调';
        return $this->render('returnpage_rentcar');
    }

    public function actionWexintext()
    {
        $view = Yii::$app->view;

        $view->params['layoutTitle']='车速递新车售卖平台喊您来买车';


        //$JSSDK =new JSSDK();
        //$JSSDK->getSignPackage();

        //$array=$JSSDK->getSignPackage();

        //$view->params['layoutLeftIcon']='icon-refresh script_refresh';
        //$view->params['layoutRightIcon']='icon-me script_account';
        //$view->params['layoutUrl']= "index.php?r=/approve/index/accountcenter";
        //var_dump($array);exit;
        return $this->render('weixintest');
        //return $this->render('weixintest',['weixininfo'=>$array]);

    }

    public function actionGetweixininfo()
    {


        $api_url= yii::$app->request->post('api_value');
        $JSSDK =new JSSDK();
        //var_dump($api_url);exit;
        $array=$JSSDK->getSignPackage($api_url);
        return json_encode($array);
    }

    public function actionGetweixinimage()
    {
        $serverId= yii::$app->request->post('serverId');
        $JSSDK =new JSSDK();
        $token=$JSSDK->getAccessToken();
        $url="http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=".$token."&media_id=".$serverId;

        try{
            $resul=$JSSDK->httpGet($url);
        }catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] ="图片下载失败"; //  服务器错误
            return json_encode($result);
        }
        $rootPath = Yii::getAlias('@tem_uploads').'/'; //上传根目录
        $randfileName = date('YmdHis',time()).rand(100000, 999999);//.".".$ext;//随机生成一个文件名
        //return $resul;
        try{
            $a = file_put_contents($rootPath.$randfileName.'.jpg',$resul );//返回的是字节数
        }catch (\Exception $ex) {
            $result['err_code'] = 40012;
            $result['err_msg'] ="图片写入失败"; //  服务器错误
            return json_encode($result);
        }
        if($a && $a>0){
            $result['img_name']=$randfileName.'.jpg';  //$rootPath.$randfileName.'.jpg';
        }else{
            $result['err_code'] = 40013;
            $result['err_msg'] ="图片存储错误"; //  服务器错误
            return json_encode($result);
        }
        return json_encode($result);

    }




}